package cn.dengta.webapp.user.vo;

import java.util.Date;

import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Formats;
import cn.dengta.webapp.base.vo.UserIdEncode;
import cn.dengta.webapp.user.cache.UserSummary;
import cn.dengta.webapp.user.entity.User;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.StringUtil;

@Getter
@Setter
public class SimpleUserVO extends MemberVO<User> implements UserIdEncode {

	/** 前端展示使用 */
	private String uId;
	/** VIP过期时间 */
	Date vipExpireTime;
	/** 是否实名认证 */
	private Boolean hasRealName;
	/** 是否真人认证 */
	private Boolean hasRealPeople;
	/** 是否头像认证 */
	private Boolean hasAvatar;
	/** 是否首次搭讪 */
	private boolean isFirstChat;

	public static SimpleUserVO of(UserSummary summary, String nickname) {
		SimpleUserVO vo = new SimpleUserVO();
		vo.setId(summary.getId());
		vo.setUId(String.valueOf(vo.getId()));
		vo.setVipExpireTime(summary.getVipExpireTime());
		vo.setNickname(StringUtil.notEmpty(nickname) ? nickname : summary.getNickname());
		vo.setGender(summary.getGender());
		vo.setHasRealName(summary.hasRealName());
		vo.setHasRealPeople(summary.hasRealPeople());
		vo.setHasAvatar(summary.isAvatared());
		vo.setAvatar(summary.avatarOrDefault());
		return vo;
	}

	public boolean getVip() {
		return vipExpireTime != null && vipExpireTime.getTime() > System.currentTimeMillis();
	}

	public String getVipExpireTime_() {
		return this.vipExpireTime != null ? Formats.formatDate_DT(this.vipExpireTime) : null;
	}

	public String getGender_() {
		return ValueProxyImpl.label(this.gender);
	}

}
